int dirA = 12;
int dirB = 13;  // not used in this example
int speedA = 3;
int speedB = 11; // not used in this example

boolean moveA = true;
boolean moveB = true;

void setup()
{  
  pinMode (dirA, OUTPUT);
  pinMode (dirB, OUTPUT);
  pinMode (speedA, OUTPUT);
  pinMode (speedB, OUTPUT);

  stopMotors();
}

void stopMotors()
{
  digitalWrite(speedA, LOW);  
  digitalWrite(speedB, LOW);  
}

void loop()
{
 
  if(moveA)
  {
    // move the motor A to one direction increasing speed
    // and stopping decreasing speed
    digitalWrite (dirA, HIGH);    
    for (int j = 0; j < 255; j += 10) {
       analogWrite (speedA, j);
       delay (500);
    }
    delay(1000); // keep the motor rolling for one second  
    for (int j = 255; j >= 0; j -= 10) {
       analogWrite (speedA, j);
       delay (500);
    }
  
    // stop the motors for 0.5 seconds
    stopMotors();
    delay(500); // keep the motor rolling for one second
  
    // move the motor A to the other direction increasing speed
    // and stopping decreasing speed
    digitalWrite (dirA, LOW);
    for (int j = 0; j < 255; j += 10) {
       analogWrite (speedA, j);
       delay (100);
    }
    delay(1000); // keep the motor rolling for one second
    for (int j = 255; j >= 0; j -= 10) {
       analogWrite (speedA, j);
       delay (100);
    }
  }
  
  
  if(moveB)
  {
    // move the motor B to one direction increasing speed
    // and stopping decreasing speed
    digitalWrite (dirB, HIGH);
    for (int j = 0; j < 255; j += 10) {
       analogWrite (speedB, j);
       delay (100);
    }
    delay(1000); // keep the motor rolling for one second  
    for (int j = 255; j >= 0; j -= 10) {
       analogWrite (speedB, j);
       delay (100);
    }
  
    // stop the motors for 0.5 seconds
    stopMotors();
    delay(500); // keep the motor rolling for one second
  
    // move the motor B to the other direction increasing speed
    // and stopping decreasing speed
    digitalWrite (dirB, LOW);
    for (int j = 0; j < 255; j += 10) {
       analogWrite (speedB, j);
       delay (100);
    }
    delay(1000); // keep the motor rolling for one second
    for (int j = 255; j >= 0; j -= 10) {
       analogWrite (speedB, j);
       delay (100);
    }
  }

  stopMotors();
  delay(3000); // keep the motor stopped for three seconds

}
